package com.helin.helinhealth;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 应用主类
 * 
 * <p>
 * 项目的启动入口，配置了MyBatis的Mapper扫描和异步任务处理。
 * 实现了ApplicationListener接口，在应用启动完成后打印访问路径信息。
 * </p>
 */
@SpringBootApplication
@MapperScan("com.helin.helinhealth.mapper")
@EnableAsync
public class HelinHealthApplication implements ApplicationListener<ContextRefreshedEvent> {
	
	private static final Logger logger = LoggerFactory.getLogger(HelinHealthApplication.class);

	public static void main(String[] args) {
		SpringApplication.run(HelinHealthApplication.class, args);
	}
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		Environment env = event.getApplicationContext().getEnvironment();
		String port = env.getProperty("server.port", "8910");
		String contextPath = env.getProperty("server.servlet.context-path", "");
		
		logger.info("\n----------------------------------------------------------\n\t" +
				"应用 '{}' 已启动! 访问路径:\n\t" +
				"本地访问: \t\thttp://localhost:{}{}\n\t" +
				"Swagger文档: \thttp://localhost:{}{}/swagger-ui/index.html\n\t" +
				"Knife4j文档: \thttp://localhost:{}{}/doc.html (推荐使用) \n" +
				"----------------------------------------------------------",
				env.getProperty("spring.application.name", "helin-health"),
				port, contextPath,
				port, contextPath,
				port, contextPath);
	}
}
